package com.iyundao.io.mapper;

import com.iyundao.io.model.SysUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface SysUserMapper {
    @Delete({
        "delete from sys_user",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String sid);

    @Insert({
        "insert into sys_user (sid, login_name, ",
        "show_name, real_name, ",
        "login_pwd, phone, ",
        "card_no, email, birthday, ",
        "sex, address, detailed, ",
        "flag, create_date, ",
        "create_id, orde_by)",
        "values (#{sid,jdbcType=CHAR}, #{loginName,jdbcType=VARCHAR}, ",
        "#{showName,jdbcType=VARCHAR}, #{realName,jdbcType=VARCHAR}, ",
        "#{loginPwd,jdbcType=VARCHAR}, #{phone,jdbcType=VARCHAR}, ",
        "#{cardNo,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{birthday,jdbcType=TIMESTAMP}, ",
        "#{sex,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, #{detailed,jdbcType=VARCHAR}, ",
        "#{flag,jdbcType=VARCHAR}, #{createDate,jdbcType=TIMESTAMP}, ",
        "#{createId,jdbcType=CHAR}, #{ordeBy,jdbcType=TINYINT})"
    })
    int insert(SysUser record);

    @InsertProvider(type=SysUserSqlProvider.class, method="insertSelective")
    int insertSelective(SysUser record);

    @Select({
        "select",
        "sid, login_name, show_name, real_name, login_pwd, phone, card_no, email, birthday, ",
        "sex, address, detailed, flag, create_date, create_id, orde_by",
        "from sys_user",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="sid", property="sid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="login_name", property="loginName", jdbcType=JdbcType.VARCHAR),
        @Result(column="show_name", property="showName", jdbcType=JdbcType.VARCHAR),
        @Result(column="real_name", property="realName", jdbcType=JdbcType.VARCHAR),
        @Result(column="login_pwd", property="loginPwd", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="card_no", property="cardNo", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="birthday", property="birthday", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="sex", property="sex", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="detailed", property="detailed", jdbcType=JdbcType.VARCHAR),
        @Result(column="flag", property="flag", jdbcType=JdbcType.VARCHAR),
        @Result(column="create_date", property="createDate", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="create_id", property="createId", jdbcType=JdbcType.CHAR),
        @Result(column="orde_by", property="ordeBy", jdbcType=JdbcType.TINYINT)
    })
    SysUser selectByPrimaryKey(String sid);

    @UpdateProvider(type=SysUserSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SysUser record);

    @Update({
        "update sys_user",
        "set login_name = #{loginName,jdbcType=VARCHAR},",
          "show_name = #{showName,jdbcType=VARCHAR},",
          "real_name = #{realName,jdbcType=VARCHAR},",
          "login_pwd = #{loginPwd,jdbcType=VARCHAR},",
          "phone = #{phone,jdbcType=VARCHAR},",
          "card_no = #{cardNo,jdbcType=VARCHAR},",
          "email = #{email,jdbcType=VARCHAR},",
          "birthday = #{birthday,jdbcType=TIMESTAMP},",
          "sex = #{sex,jdbcType=VARCHAR},",
          "address = #{address,jdbcType=VARCHAR},",
          "detailed = #{detailed,jdbcType=VARCHAR},",
          "flag = #{flag,jdbcType=VARCHAR},",
          "create_date = #{createDate,jdbcType=TIMESTAMP},",
          "create_id = #{createId,jdbcType=CHAR},",
          "orde_by = #{ordeBy,jdbcType=TINYINT}",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(SysUser record);
}